package hz.mobileproject.pda.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.ui.activity.work.AssetsTakingActivity;

/**
 * Created by hasee on 2017/11/16.
 */

public class AssetsTakingAdapter extends BaseAdapter {

    private List<AssetsTakingActivity.AssetsTakingBean> mList;

    private LayoutInflater mInflater;

    private Context mContext;

    public AssetsTakingAdapter(Context context, List<AssetsTakingActivity.AssetsTakingBean> list){
        mContext = context;
        mList = list;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList == null ? null : mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if(view == null){
            view = mInflater.inflate(R.layout.assets_taking_list_item, null);
            vh = new ViewHolder(view);
            view.setTag(vh);
        }else{
            vh = (ViewHolder) view.getTag();
        }
        vh._name.setText(mList.get(i).getName());
        vh._code.setText(mList.get(i).getCode());
        vh._type.setText(mList.get(i).getCheckType());
        if(mList.get(i).getState() == AssetsTakingActivity.AssetsTakingBean.STATE_FINISH){
            if(mList.get(i).getFinishType() == AssetsTakingActivity.AssetsTakingBean.FINISHTYPE_OK){
                vh._state.setText("已盘点（正常）");
                vh._state.setTextColor(Color.parseColor("#00ff00"));
            }else{
                vh._state.setText("已盘点（异常）");
                vh._state.setTextColor(Color.parseColor("#ff5100"));
            }
        }else if(mList.get(i).getState() == AssetsTakingActivity.AssetsTakingBean.STATE_UNFINISH){
            vh._state.setText("未盘点");
            vh._state.setTextColor(Color.parseColor("#ff5100"));
        }
        vh._name.setText(mList.get(i).getName());

        return view;
    }

    static class ViewHolder{
        private TextView _name;
        private TextView _code;
        private TextView _type;
        private TextView _state;
        public ViewHolder(View v) {
            _name = (TextView) v.findViewById(R.id.tv_name_assets);
            _code = (TextView) v.findViewById(R.id.tv_code_assets);
            _type = (TextView) v.findViewById(R.id.tv_type_assets);
            _state = (TextView) v.findViewById(R.id.tv_state_assets);
        }
    }

}
